﻿<cfsilent>
	<cfscript>

		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");

		response = structNew();
		structInsert(response, "success", false, true);

		taskId = event.getArg("TSK");
		taskType = event.getArg("TT");

		taskPeriod = event.getArg("TP");
		taskWeekStart = event.getArg("TWS");
		taskWeekEnd = event.getArg("TWE");

		transaction {
			
			/* 载入教学任务 */
			
			/* 修改教学班周次及周学时 */
			switch(taskType){
				case 'P':
					sql = "UPDATE t_task a 
							SET a.task_week = :TaskWeek ,
                 				a.task_period = :TaskPeriod 
							WHERE a.tsk_id = :taskId ";
					break;
				case 'C':
					sql = "UPDATE t_common_task a 
							SET a.task_week = :TaskWeek ,
                 				a.task_period = :TaskPeriod 
							WHERE a.tsk_id = :taskId ";
					break;
				case 'R':
					sql = "UPDATE t_reopen_task a 
							SET a.task_week = :TaskWeek ,
                 				a.task_period = :TaskPeriod  
							WHERE a.tsk_id = :taskId ";
					break;
				case 'T':
					sql = "UPDATE t_sport_task a 
							SET a.task_week = :TaskWeek ,
                 				a.task_period = :TaskPeriod 
							WHERE a.tsk_id = :taskId ";
					break;
			}
			
			updateObj = new Query(datasource=application.dnsMaster);
			updateObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
			updateObj.addParam(name="TaskWeek", value= numberFormat(taskWeekStart, "0_") & "-" & numberFormat(taskWeekEnd, "0_") , cfsqltype="cf_sql_char");
			updateObj.addParam(name="TaskPeriod", value=taskPeriod, cfsqltype="cf_sql_varchar");
			updateObj.execute(sql=sql);
			
			/* 载入排课任务 */
			
			/* 计算需排课总学时 */
			periodCount = 0;
			periodArray = listToArray(taskPeriod, "+");
			
			for ( pd in periodArray ) {
				periodCount = periodCount + pd;
			}
			
			period = (taskWeekEnd - taskWeekStart + 1) * periodCount;
			
			/* 设置需排总学时 */
			
			sql = "UPDATE t_task_arrange a 
					SET a.period_need = :PeriodNeed  
					WHERE a.task_id = :taskId ";
					
			updateObj = new Query(datasource = application.dnsMaster);
			updateObj.addParam(name ="PeriodNeed", value=period, cfsqltype="cf_sql_interger");
			updateObj.addParam(name="taskId", value=taskId, cfsqltype="cf_sql_varchar");
			updateObj.execute(sql = sql);
			
			structInsert(response, "success", true, true);
			
		}

	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>